import java.util.ArrayList;
import java.util.List;

class TreeNode {
    int val;
    TreeNode left;
    TreeNode right;
    TreeNode() {}
    TreeNode(int val) { this.val = val; }
    TreeNode(int val, TreeNode left, TreeNode right) {
        this.val = val;
        this.left = left;
        this.right = right;
    }
}


public class project {
    public int[] searchRange(int[] nums, int target) {
        int len=nums.length;
        if(len==0){
            return new int[]{-1,-1};
        }
        int left=0;
        int right=len-1;
        while (left<right){
            int mid=(left+right)/2;
            if(nums[mid]>=target){
                right=mid;
            }else{
                left=mid+1;
            }
        }
        if(nums[right]!=target){
            return new int[]{-1,-1};
        }
        int index=right;
        left=0;
        right=len-1;
        while (left<right){
            int mid=(right+left+1)/2;
            if(nums[mid]<=target){
                left=mid;
            }else{
                right=mid-1;
            }
        }
        return new int[]{index,right};
    }

















    public List<Integer> findDuplicates(int[] nums) {
        List<Integer> list=new ArrayList<>();
        for(int i=0;i<nums.length;i++){
            int j=i;
            while (nums[j]!=j+1){
                if(nums[j]==nums[nums[j]-1]){
                    break;
                }
                int tmp=nums[j];
                nums[j]=nums[nums[j]-1];
                nums[tmp-1]=tmp;
            }
        }
        for(int i=0;i<nums.length;i++){
            if(nums[i]!=i+1){
                list.add(nums[i]);
            }
        }
        return list;
    }














    public TreeNode removeLeafNodes(TreeNode root, int target) {
        if(root==null){
            return null;
        }
        root.left=removeLeafNodes(root.left,target);
        root.right=removeLeafNodes(root.right,target);
        if(root.left==null&&root.right==null&&target==root.val){
            root=null;
        }
        return root;
    }












    public int poorPigs(int buckets, int minutesToDie, int minutesToTest) {
        int states = minutesToTest / minutesToDie + 1;
        int pigs = (int) Math.ceil(Math.log(buckets) / Math.log(states));
        return pigs;
    }
}
